package team.nmsg.ge.system.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashSet;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;

import team.nmsg.photo.PhotoUtil;
import team.nmsg.photo.util.WxUtil;

public class ServerParams {
	
	
	public static String BASIC_STATIC_DIR;
	
	public static String ENCODE = "UTF-8";
	public static final long SESSION_TIMEOUT = 60*1000*60;
	public static final String NOLOGIN_KEY = "_noLogin_";
	public static final String NOPERMIT_KEY = "_noPermit_";
	public static final String NOAUTH_URL = "/noAuth";
	public static String SERVER_ERROR_KEY = "_serverError_";
	public static Set<String> denyDir = new HashSet<String>();
	
	public static int MYSQL_PORT = 3306;
	public static String MYSQL_HOST = "127.0.0.1";
	public static String MYSQL_DB = "nmsdb";
	
	public static String BASE_CONF_PATH = "config/";
	public static String COMPANYLOGO_PATH = "resources/img/companylogo/";
	
	public static Properties pros = new Properties();
	public static String dbUrl;
	public static String dbDrivername;
	public static String dbUsername;
	public static String dbPassword;
	public static String ADMIN_NAME = "Admin";
	
	public static String SYS_NAME = "SYS";
	public static String SYS_VERSION = "SYS";

	
    public static Locale ZH_CN = new Locale("zh", "CN"); 
    public static Locale EN_US = new Locale("en", "US"); 
    public static Locale locale = ZH_CN;
    public static String strLocale = "ZH_CN";
    public static String LOCAL_ZH_CN_STR = "zh-CN";
    public static String LOCAL_EN_US_STR = "en-US";

    public static int WEBSOCKET_PORT = 11112;
    
    
    public static String photomurl = "";
    
    public static void initServerParams(){

    	File conf = new File( BASE_CONF_PATH+"serverpro.properties");
    	FileInputStream fis = null;
    	try {
    		String userDir = System.getProperty("user.dir");
			userDir = userDir.replace("\\", "/");
			BASIC_STATIC_DIR = userDir + "/resources/";
    		
    		fis = new FileInputStream(conf);
			pros.load( fis );
			
			MYSQL_HOST = pros.getProperty("MYSQL_HOST");
			MYSQL_DB = pros.getProperty("MYSQL_DB");
			MYSQL_PORT =  Integer.parseInt( pros.getProperty("MYSQL_PORT") );
			
			SYS_NAME = pros.getProperty("SYS_NAME");
			SYS_VERSION = pros.getProperty("SYS_VERSION");
			
			photomurl = pros.getProperty("photomurl");
			
			strLocale = pros.getProperty("locale") ;
			if(  "ZH_CN".equals(strLocale) ){
				locale = ZH_CN;
			}else if(  "EN_US".equals(strLocale) ){
				locale = EN_US;
			}
			
			PhotoUtil.initDir();
			WxUtil.init();
			
		} catch ( Exception e) {
			e.printStackTrace();
		}  finally{
			try {
				fis.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
    	
    }
    
	
}
